package com.ck.chuangke.controller;

import com.ck.constant.BusinessConstant;
import com.ck.constant.DateFormatConstant;
import com.ck.chuangke.service.CkCompanyService;
import com.ck.chuangke.service.CkDeviceInfoService;
import com.ck.chuangke.service.CkProgramService;
import com.ck.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;

/**
 * @ClassName CkWebController
 * @Description 处理创客后台公共Controller问题
 * @Author HanQinrui
 * @Date 2018/6/21 10:39
 * @Version 1.0
 **/
@Controller
@RequestMapping(value = "/ckWeb")
public class CkWebController {

    @Autowired
    private CkCompanyService ckCompanyService;
    @Autowired
    private CkProgramService ckProgramService;
    @Autowired
    private CkDeviceInfoService ckDeviceInfoService;

    @RequestMapping(value = "/goHome")
    public String goHome(Model model) {
        // 实时日期
        String currentDate = DateUtils.longTimeStampToStringDate(System.currentTimeMillis(), DateFormatConstant.DATE_SHORT_ISO);
        model.addAttribute("currentDate", currentDate);
        // 商家总数
        Long companyCount = ckCompanyService.getCompanyCount();
        model.addAttribute("companyCount", companyCount);
        // 终端总数
        Long deviceCount = ckDeviceInfoService.getDeviceCount();
        model.addAttribute("deviceCount", deviceCount);
        // 节目总数
        Long programCount = ckProgramService.getProgramCount();
        model.addAttribute("programCount", programCount);
        // 已审批节目总数
        Long passProgramCount = ckProgramService.getProgramCountByStatus(BusinessConstant.PROGRAM_STATUS_PASS);
        model.addAttribute("passProgramCount", passProgramCount);

        // ------------------------------------东北大区 start------------------------------------------
        HashMap<String, Long> northEastMap = new HashMap<>(4);
        // 东北大区终端总数
        Long northEastDeviceCount = ckDeviceInfoService.getDeviceCountByRegion(BusinessConstant.REGION_NORTH_EAST);
        northEastMap.put("northEastDeviceCount", northEastDeviceCount);
        // 东北大区在线终端总数
        Long northEastOnlineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_NORTH_EAST,BusinessConstant.DEVICE_INFO_STATUS_ON_LINE);
        northEastMap.put("northEastOnlineDeviceCount", northEastOnlineDeviceCount);
        // 东北大区离线终端总数
        Long northEastOfflineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_NORTH_EAST,BusinessConstant.DEVICE_INFO_STATUS_OFF_LINE);
        northEastMap.put("northEastOfflineDeviceCount", northEastOfflineDeviceCount);
        // 东北大区节目总数
        Long northEastProgramCount = ckProgramService.getProgramCountByRegion(BusinessConstant.REGION_NORTH_EAST);
        northEastMap.put("northEastProgramCount", northEastProgramCount);
        model.addAttribute("northEastMap", northEastMap);
        // ------------------------------------东北大区 end------------------------------------------

        // ------------------------------------华北大区 start------------------------------------------
        HashMap<String, Long> northChinaMap = new HashMap<>(4);
        // 华北大区终端总数
        Long northChinaDeviceCount = ckDeviceInfoService.getDeviceCountByRegion(BusinessConstant.REGION_NORTH_CHINA);
        northChinaMap.put("northChinaDeviceCount", northChinaDeviceCount);
        // 华北大区在线终端总数
        Long northChinaOnlineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_NORTH_CHINA,BusinessConstant.DEVICE_INFO_STATUS_ON_LINE);
        northChinaMap.put("northChinaOnlineDeviceCount", northChinaOnlineDeviceCount);
        // 华北大区离线终端总数
        Long northChinaOfflineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_NORTH_CHINA,BusinessConstant.DEVICE_INFO_STATUS_OFF_LINE);
        northChinaMap.put("northChinaOfflineDeviceCount", northChinaOfflineDeviceCount);
        // 华北大区节目总数
        Long northChinaProgramCount = ckProgramService.getProgramCountByRegion(BusinessConstant.REGION_NORTH_CHINA);
        northChinaMap.put("northChinaProgramCount", northChinaProgramCount);
        model.addAttribute("northChinaMap", northChinaMap);
        // ------------------------------------华北大区 end------------------------------------------

        // ------------------------------------华中大区 start------------------------------------------
        HashMap<String, Long> centralChinaMap = new HashMap<>(4);
        // 华中大区终端总数
        Long centralChinaDeviceCount = ckDeviceInfoService.getDeviceCountByRegion(BusinessConstant.REGION_CENTRAL_CHINA);
        centralChinaMap.put("centralChinaDeviceCount", centralChinaDeviceCount);
        // 华中大区在线终端总数
        Long centralChinaOnlineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_CENTRAL_CHINA,BusinessConstant.DEVICE_INFO_STATUS_ON_LINE);
        centralChinaMap.put("centralChinaOnlineDeviceCount", centralChinaOnlineDeviceCount);
        // 华中大区离线终端总数
        Long centralChinaOfflineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_CENTRAL_CHINA,BusinessConstant.DEVICE_INFO_STATUS_OFF_LINE);
        centralChinaMap.put("centralChinaOfflineDeviceCount", centralChinaOfflineDeviceCount);
        // 华中大区节目总数
        Long centralChinaProgramCount = ckProgramService.getProgramCountByRegion(BusinessConstant.REGION_CENTRAL_CHINA);
        centralChinaMap.put("centralChinaProgramCount", centralChinaProgramCount);
        model.addAttribute("centralChinaMap", centralChinaMap);
        // ------------------------------------华中大区 end------------------------------------------

        // ------------------------------------华东大区 start------------------------------------------
        HashMap<String, Long> eastChinaMap = new HashMap<>(4);
        // 华东大区终端总数
        Long eastChinaDeviceCount = ckDeviceInfoService.getDeviceCountByRegion(BusinessConstant.REGION_EAST_CHINA);
        eastChinaMap.put("eastChinaDeviceCount", eastChinaDeviceCount);
        // 华东大区在线终端总数
        Long eastChinaOnlineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_EAST_CHINA,BusinessConstant.DEVICE_INFO_STATUS_ON_LINE);
        eastChinaMap.put("eastChinaOnlineDeviceCount", eastChinaOnlineDeviceCount);
        // 华东大区离线终端总数
        Long eastChinaOfflineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_EAST_CHINA,BusinessConstant.DEVICE_INFO_STATUS_OFF_LINE);
        eastChinaMap.put("eastChinaOfflineDeviceCount", eastChinaOfflineDeviceCount);
        // 华东大区节目总数
        Long eastChinaProgramCount = ckProgramService.getProgramCountByRegion(BusinessConstant.REGION_EAST_CHINA);
        eastChinaMap.put("eastChinaProgramCount", eastChinaProgramCount);
        model.addAttribute("eastChinaMap", eastChinaMap);
        // ------------------------------------华东大区 end------------------------------------------

        // ------------------------------------华南大区 start------------------------------------------
        HashMap<String, Long> southChinaMap = new HashMap<>(4);
        // 华南大区终端总数
        Long southChinaDeviceCount = ckDeviceInfoService.getDeviceCountByRegion(BusinessConstant.REGION_SOUTH_CHINA);
        southChinaMap.put("southChinaDeviceCount", southChinaDeviceCount);
        // 华南大区在线终端总数
        Long southChinaOnlineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_SOUTH_CHINA,BusinessConstant.DEVICE_INFO_STATUS_ON_LINE);
        southChinaMap.put("southChinaOnlineDeviceCount", southChinaOnlineDeviceCount);
        // 华南大区离线终端总数
        Long southChinaOfflineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_SOUTH_CHINA,BusinessConstant.DEVICE_INFO_STATUS_OFF_LINE);
        southChinaMap.put("southChinaOfflineDeviceCount", southChinaOfflineDeviceCount);
        // 华南大区节目总数
        Long southChinaProgramCount = ckProgramService.getProgramCountByRegion(BusinessConstant.REGION_SOUTH_CHINA);
        southChinaMap.put("southChinaProgramCount", southChinaProgramCount);
        model.addAttribute("southChinaMap", southChinaMap);
        // ------------------------------------华南大区 end------------------------------------------

        // ------------------------------------西北大区 start------------------------------------------
        HashMap<String, Long> westNorthMap = new HashMap<>(4);
        // 西北大区终端总数
        Long westNorthDeviceCount = ckDeviceInfoService.getDeviceCountByRegion(BusinessConstant.REGION_WEST_NORTH);
        westNorthMap.put("westNorthDeviceCount", westNorthDeviceCount);
        // 西北大区在线终端总数
        Long westNorthOnlineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_WEST_NORTH,BusinessConstant.DEVICE_INFO_STATUS_ON_LINE);
        westNorthMap.put("westNorthOnlineDeviceCount", westNorthOnlineDeviceCount);
        // 西北大区离线终端总数
        Long westNorthOfflineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_WEST_NORTH,BusinessConstant.DEVICE_INFO_STATUS_OFF_LINE);
        westNorthMap.put("westNorthOfflineDeviceCount", westNorthOfflineDeviceCount);
        // 西北大区节目总数
        Long westNorthProgramCount = ckProgramService.getProgramCountByRegion(BusinessConstant.REGION_WEST_NORTH);
        westNorthMap.put("westNorthProgramCount", westNorthProgramCount);
        model.addAttribute("westNorthMap", westNorthMap);
        // ------------------------------------西北大区 end------------------------------------------

        // ------------------------------------西南大区 start------------------------------------------
        HashMap<String, Long> westSouthMap = new HashMap<>(4);
        // 西南大区终端总数
        Long westSouthDeviceCount = ckDeviceInfoService.getDeviceCountByRegion(BusinessConstant.REGION_WEST_SOUTH);
        westSouthMap.put("westSouthDeviceCount", westSouthDeviceCount);
        // 西南大区在线终端总数
        Long westSouthOnlineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_WEST_SOUTH,BusinessConstant.DEVICE_INFO_STATUS_ON_LINE);
        westSouthMap.put("westSouthOnlineDeviceCount", westSouthOnlineDeviceCount);
        // 西南大区离线终端总数
        Long westSouthOfflineDeviceCount = ckDeviceInfoService.getDeviceCountByRegionAndStatus(BusinessConstant.REGION_WEST_SOUTH,BusinessConstant.DEVICE_INFO_STATUS_OFF_LINE);
        westSouthMap.put("westSouthOfflineDeviceCount", westSouthOfflineDeviceCount);
        // 西南大区节目总数
        Long westSouthProgramCount = ckProgramService.getProgramCountByRegion(BusinessConstant.REGION_WEST_SOUTH);
        westSouthMap.put("westSouthProgramCount", westSouthProgramCount);
        model.addAttribute("westSouthMap", westSouthMap);
        // ------------------------------------西南大区 end------------------------------------------

        return "ck/ck_home";
    }
}
